package com.itshare.video.controller;

import com.itshare.video.aop.annontations.AccountFreezeCheck;
import com.itshare.video.common.annontation.AttrData;
import com.itshare.video.common.annontation.WebData;
import com.itshare.video.common.aop.xss.annontation.CleanXSS;
import com.itshare.video.common.core.validator.support.value.NumMustIn;
import com.itshare.video.common.dto.Result;
import com.itshare.video.pojo.dto.UserTokenDTO;
import com.itshare.video.service.CategoryService;
import com.itshare.video.service.UserService;
import lombok.Data;
import org.hibernate.validator.constraints.URL;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.Duration;

/**
 * @Author lyr
 * @create 2020/10/24 21:07
 */
@Validated
@RestController
@RequestMapping("/api/")
public class TestController {
    @Resource
    private CategoryService categoryService;


    public String getById(int id) {
        categoryService.getCategoryList();
        System.out.println("oooo");
        return "xx";
    }


    @GetMapping("test")
    public String ok(@AttrData UserTokenDTO userTokenDTO, @RequestParam() @NumMustIn(anyIn = {1, 2, 4}, message = "数据必须在1,2,4") Integer i) {
        // getById(1);
        return "fuck";
    }

    @Resource
    private UserService userService;

    @AccountFreezeCheck
    @GetMapping("/account_test")
    public Result okkk(@AttrData UserTokenDTO userTokenDTO) {

        userService.setUserAccountFreezeForUpload(userTokenDTO.getId(), Duration.ofDays(1));
        return Result.success();
    }

    @Data
    static class Content {
        @CleanXSS(type = CleanXSS.type.RemoveScriptThenEscape)
        String content;
    }


    @GetMapping("/url")
    @CleanXSS
    public Result<String> ooo(@RequestParam
                              @CleanXSS String content, @RequestBody Content content2) {
        System.out.println(content);
        System.out.println(content2);
        return Result.success();
    }


    @RequestMapping("/sss")
    public Result ooooo(@URL() @RequestParam String content) {
        return Result.success();
    }


    @Data
    public static class URLData1 {
        @URL
        public String url;
        public String name;


    }


    @RequestMapping("/xxx1")
    public String oosssss(@WebData @Validated URLData1 userTokenDTO) {
        System.out.println(userTokenDTO);
        return "OKK";
    }


}
